package com.new_wear.project.system.illegal.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.new_wear.framework.aspectj.lang.annotation.Log;
import com.new_wear.framework.aspectj.lang.enums.BusinessType;
import com.new_wear.project.system.illegal.domain.Illegal;
import com.new_wear.project.system.illegal.service.IIllegalService;
import com.new_wear.framework.web.controller.BaseController;
import com.new_wear.framework.web.domain.AjaxResult;
import com.new_wear.common.utils.poi.ExcelUtil;
import com.new_wear.framework.web.page.TableDataInfo;

/**
 * 违法信息Controller
 * 
 * @author new_wear
 * @date 2019-12-23
 */
@Controller
@RequestMapping("/system/illegal")
public class IllegalController extends BaseController
{
    private String prefix = "system/illegal";

    @Autowired
    private IIllegalService illegalService;

    @RequiresPermissions("system:illegal:view")
    @GetMapping()
    public String illegal()
    {
        return prefix + "/illegal";
    }

    /**
     * 查询违法信息列表
     */
    @RequiresPermissions("system:illegal:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Illegal illegal)
    {
        startPage();
        List<Illegal> list = illegalService.selectIllegalList(illegal);
        return getDataTable(list);
    }

    /**
     * 导出违法信息列表
     */
    @RequiresPermissions("system:illegal:export")
    @Log(title = "违法信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Illegal illegal)
    {
        List<Illegal> list = illegalService.selectIllegalList(illegal);
        ExcelUtil<Illegal> util = new ExcelUtil<Illegal>(Illegal.class);
        return util.exportExcel(list, "illegal");
    }

    /**
     * 新增违法信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存违法信息
     */
    @RequiresPermissions("system:illegal:add")
    @Log(title = "违法信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Illegal illegal)
    {
        return toAjax(illegalService.insertIllegal(illegal));
    }

    /**
     * 修改违法信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Illegal illegal = illegalService.selectIllegalById(id);
        mmap.put("illegal", illegal);
        return prefix + "/edit";
    }

    /**
     * 修改保存违法信息
     */
    @RequiresPermissions("system:illegal:edit")
    @Log(title = "违法信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Illegal illegal)
    {
        return toAjax(illegalService.updateIllegal(illegal));
    }

    /**
     * 删除违法信息
     */
    @RequiresPermissions("system:illegal:remove")
    @Log(title = "违法信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(illegalService.deleteIllegalByIds(ids));
    }
}
